//
//  FLNSubTableViewCell.m
//  百思不得姐
//
//  Created by xmg on 16/6/4.
//  Copyright © 2016年 FLN.com. All rights reserved.
//

#import "FLNSubTableViewCell.h"
#import "FLNSubTagItem.h"
#import <UIImageView+WebCache.h>

@interface FLNSubTableViewCell ()
@property (weak, nonatomic) IBOutlet UIImageView *iconView;
@property (weak, nonatomic) IBOutlet UILabel *nameView;
@property (weak, nonatomic) IBOutlet UILabel *numView;

@end

@implementation FLNSubTableViewCell

- (void)setFrame:(CGRect)frame {

    frame.origin.y += 5;
    frame.size.height -= 5;
    frame.origin.x += 5;
    frame.size.width -= 10;
    
    [super setFrame:frame];

}


- (void)awakeFromNib {
//    头像圆角
    _iconView.layer.cornerRadius = _iconView.width / 2;
    //超出主层边框裁剪掉
    _iconView.layer.masksToBounds = YES;
}

+ (instancetype)viewForXib {
    
    return [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:nil options:nil] firstObject];

}

- (void)setItem:(FLNSubTagItem *)item {

    _item = item;
    //给子控件赋值
    //头像
    [_iconView sd_setImageWithURL:[NSURL URLWithString:item.image_list] placeholderImage:[UIImage imageNamed:@"defaultUserIcon"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        
        //开启图形上下文
        //0 : 自动识别当前比例
        UIGraphicsBeginImageContextWithOptions(image.size, NO, 0);
        //描述圆形路劲
        UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, image.size.width, image.size.height)];
        //设置裁剪区域
        [path addClip];
        
        //绘制图片
        [image drawAtPoint:CGPointZero];
        
        //从上下文抽取图片
        image = UIGraphicsGetImageFromCurrentImageContext();
        //关闭上下文
        UIGraphicsEndPDFContext();
        //设置圆形图片
        _iconView.image = [image imageAntialias];
        
    }];

    _nameView.text = item.theme_name;
    
    
    //数字
    NSString *num = @"10000";
    CGFloat number = [num floatValue];
    num = [NSString stringWithFormat:@"%@个美女订阅",num];
    
    if (number >= 10000) {
        number = number / 10000.0;
        num = [NSString stringWithFormat: @"%.1f万个美女订阅",number];
    }
    
    _numView.text = num;
}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
